/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"C71FA99C-5D5E-4D6A-9F0D-4D97DD7E81E3",variableType:4}
 */
var entero = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"83B895EF-017F-4118-9E7C-DAE67BFE756B",variableType:8}
 */
var fIva_1 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"0C91AF03-1974-4AB9-BC37-D0782D7EE149",variableType:8}
 */
var fIva_2 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"9AA56754-7EE3-4B38-A062-11D2568CC606",variableType:8}
 */
var fIva_3 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"97AEA529-B7E9-4EBC-9959-6D26BF8C96D3",variableType:8}
 */
var fIva_4 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"9341D4F8-8022-4090-AF45-45E3D5DD310C",variableType:8}
 */
var fNeto_1 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"9A192B1E-87A2-4F6E-91D4-D1FDDACAA532",variableType:8}
 */
var fNeto_2 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"FCE73F69-C8E5-4235-A93D-A2DF67BD4AF4",variableType:8}
 */
var fNeto_3 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"6A5B0074-79C0-4ED0-BC0A-288D1A9657B3",variableType:8}
 */
var fNeto_4 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"6856F469-2A4B-4456-AD33-2EDFBC538D3C",variableType:8}
 */
var porc_1 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"0287E229-5CA6-49D0-B456-36BD17DB5271",variableType:8}
 */
var porc_2 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"97277C5B-FAEF-4F74-9B5D-283F5F4F2F3B",variableType:8}
 */
var porc_3 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"529E5902-62B8-409F-BA2F-326E5392F834",variableType:8}
 */
var porc_4 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"DDD324D4-83D5-4662-AA29-0D63A570573C",variableType:8}
 */
var T_importe = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"77F7954B-06D8-42D5-803F-903F168CAC8B",variableType:8}
 */
var T_iva = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"DCD001D9-AAE4-4B6B-8349-65E3840F6BED",variableType:8}
 */
var T_neto = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"CE8BACB6-3769-45D1-B675-D1DBE051EE20",variableType:8}
 */
var T_neto_no_gravado = null;

/**
 *
 * @properties={typeid:24,uuid:"BB3FC3B2-1D9F-4CB7-9B0D-CF9442CA4409"}
 */
function calcular_totales()
{
	//application.output('calcular totales')
	// arma dataset
	//**//var tabla_totales = databaseManager.createEmptyDataSet(50,3)   habilitar cuando funcione
	var tabla_totales = databaseManager.createEmptyDataSet(10,3)
	
	//**//for ( var k = 0 ; k < 50 ; k ++ )
	for ( var k = 0 ; k < 10 ; k ++ )
	{
		tabla_totales.setValue(k, 1, 0.00);
		tabla_totales.setValue(k, 2, 0.00);
		tabla_totales.setValue(k, 3, 0.00);	
	}
	
	// recorre foundset
	T_neto=0
	T_iva=0
	T_importe=0
	T_neto_no_gravado=0  // 07/06/2010 
	
	var $ctos = databaseManager.getFoundSetCount(foundset)
	for ( var i = 1 ; i <= $ctos; i++ )
	{
		var $rcd = foundset.getRecord(i)
		
		//  usando calculations
		if ($rcd.letra != 'E')
		{
			T_neto 				+= $rcd.neto_signo;
			T_neto_no_gravado 	+= $rcd.neto_no_gravado_signo;
		}
		else
			T_neto_no_gravado 	+= $rcd.neto_no_gravado_signo_diario; 
		
		T_iva 		+= $rcd.iva_signo;
		T_importe 	+= $rcd.importe_signo;
		
		var k = $rcd.ctacte_cl_to_tasa_iva_porc.tasa_iva_id
			
		tabla_totales.setValue(k, 1, $rcd.iva_porc)
		tabla_totales.setValue(k, 2, tabla_totales.getValue(k, 2) + $rcd.iva_signo)
		if (letra != 'E')
			tabla_totales.setValue(k, 3, tabla_totales.getValue(k, 3) + $rcd.neto_signo);

		var lineas_hoja = 32 
//		$rcd.saldo_aux = Math.floor((i-1)/lineas_hoja) + globals.ghoja_desde_diario + 1
		if (i%lineas_hoja == 0)
			$rcd.saldo_aux = (i/lineas_hoja) + globals.ghoja_desde_diario
		if (i == $ctos && i%lineas_hoja != 0)
			$rcd.saldo_aux = Math.floor(i/lineas_hoja) + globals.ghoja_desde_diario + 1
	}
	
	for ( var k = 1 ; k <= 10 ; k ++ )
	{
		if (tabla_totales.getValue(k, 1) != 0 && tabla_totales.getValue(k, 2) != 0 && tabla_totales.getValue(k, 3) != 0)		
		{ /*
			application.output(k)
			application.output('porcentaje')
			application.output(tabla_totales.getValue(k, 1))
			application.output('iva')
			application.output(tabla_totales.getValue(k, 2))
			application.output('neto')
			application.output(tabla_totales.getValue(k, 3)) */
		}
		else
		{
			//	application.output('son todos ceros')
			fIva_1=tabla_totales.getValue(1, 2)
			fIva_2=tabla_totales.getValue(2, 2)
			fIva_3=tabla_totales.getValue(3, 2)
			fIva_4=tabla_totales.getValue(4, 2)
			porc_1=tabla_totales.getValue(1, 1)
			porc_2=tabla_totales.getValue(2, 1)
			porc_3=tabla_totales.getValue(3, 1)
			porc_4=tabla_totales.getValue(4, 1)
			fNeto_1=tabla_totales.getValue(1, 3)
			fNeto_2=tabla_totales.getValue(2, 3)
			fNeto_3=tabla_totales.getValue(3, 3)
			fNeto_4=tabla_totales.getValue(4, 3)
		}
	}               
}
